package com.rankeiot.core.event;

import com.rankeiot.core.config.IConfigItem;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.springframework.context.ApplicationEvent;

import java.util.HashSet;
import java.util.Objects;
import java.util.Set;


public class ConfigChangeEvent extends ApplicationEvent {
    private final Set<String> changeKeys;

    public ConfigChangeEvent(Object source,Set<String> changeKeys) {
        super(source);
        this.changeKeys=changeKeys;
    }

    /**
     * 检测配置是否有变动
     * @param keys
     * @return
     */
    public boolean anyChangeOf(IConfigItem...keys){
        for(IConfigItem e:keys){
           if(changeKeys.contains(e.fullName())){
               return true;
           }
        }
        return false;
    }

    public Set<String> getChangeKeys() {
        return changeKeys;
    }
}
